import base from './axiosInstance'

const origin = import.meta.env.MODE == 'development'?'https:aimeta.huilan.com:32108/':window.location.origin
const axios = base.axios
const baseApiUrl = base.baseApiUrl
const baseAihumanConfigApiUrl = base.baseAihumanApiConfigUrl
const baseAihumanEngineApiUrl = base.baseAihumanApiEngineUrl
const baseAihumanCoreBusiniessApiUrl = base.baseAihumanCoreBusiniessApiUrl

/**
 * 获取项目配置
 */
export function getProjectAllConfigInfo(data: any) {
  return axios({
    method:'post',
    baseURL: `${baseAihumanCoreBusiniessApiUrl}/aimetaProjectManager/getProjectAllConfigInfo`,
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
      // satoken: token
    },
    data
  }).then(res=>{
    return res.data
  })
}
/**
 * 获取数字人配置
 */
export function getAimetaManagerdetailInfo(data: any) {
  return axios({
    method:'post',
    baseURL: `${baseAihumanCoreBusiniessApiUrl}/aimetaManager/detail`,
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
      // satoken: token
    },
    params:data
    
  }).then(res=>{
    return res.data
  })
}
/**
 * 获取项目详情
 */
export function getAimetaProjectManagerdetailInfo(data: any) {
  return axios({
    method:'post',
    baseURL: `${baseAihumanCoreBusiniessApiUrl}/aimetaProjectManager/detail`,
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
      // satoken: token
    },
    params:data
  }).then(res=>{
    return res.data
  })
}
/**
 * 开始接口，获取房间token
 * configJson object 配置json
 * clientType integer 客户端类型 1:前端 2:渲染端 3:流程引擎
 */
export function getTokenToBegin(data: any) {
  return axios({
    method:'post',
    baseURL: `${baseAihumanEngineApiUrl}/coreRobot/begin`,
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
      // satoken: token
    },
    data
  }).then(res=>{
    return res.data
  })
}

//ue
export const driveUeApi = (data) => {

  let formData = new FormData();
  formData.append("param", JSON.stringify({ ...data }));

  return axios({
    url: `${baseApiUrl}/aihuman-web/ueApi/answer/broadcastOriginal`,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  })
}




/**
 * 问答
 */
export function toGetAnswer(data: any) {
  return axios({
    method:'post',
    baseURL: `${baseApiUrl}/aimetaflow/api/aimetaflow-coreBusiness/coreRobot/toGetAnswer`,
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
      // satoken: token
    },
    data
  }).then(res=>{
    return res.data
  })
}
/**
 * 问答带tag
 */
export function askForCall(data: any) {
  return axios({
    // baseURL: `${baseApiUrl}/aimetaflow/api/aimetaflow-robot/huilan-robot-answer/askForCall`,
    baseURL: `${baseAihumanEngineApiUrl}/coreRobot/askForCallByConfig`,
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
      // Satoken: 'e03cb4c8-2370-4184-9474-b37ba593ef15'
    },
    method:'post',
    data
  }).then(res=>{
    return res.data
  })
}

/**
 * 获取音频转文字
 * @param data
 */
export function getAudioToText(data:any) {
  return axios({
    method:'post',
    baseURL: `${baseAihumanEngineApiUrl}/coreRobot/asrForUploadFileWithHuilanByConfig`,
    data
  }).then(res=>{
    return res.data
  })
}
/**
 * 文字转音频
 * @param params
 */
export function ttsApi(data:any) {
  return axios({
    method:'post',
    baseURL: `${baseAihumanEngineApiUrl}/coreRobot/tts`,
    data,
    responseType:data.responseType?data.responseType:'blob'
  }).then(res=>{
    return res.data
  })
}
/**
 * 退出时关闭房间接口
 * @param params
 */
export function closeRoom(data:any) {
  return axios({
    method:'post',
    baseURL: `${baseAihumanEngineApiUrl}/coreRobot/closeRoom`,
    data,
  }).then(res=>{
    console.log('退出时关闭房间')
    return res.data
  })
  // navigator.sendBeacon(`${baseAihumanEngineApiUrl}/coreRobot/closeRoom`, JSON.stringify(data));
  
}

/**
 * 获取lottie svg动画json文件
 * @param params
 */
export function getSvgJsonFile(data:any) {
  return axios({
    method: 'get',
    baseURL: data.url,
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
    }
  }).then(res=>{
    return res.data
  })
}
/**
 * 获取minio tts音频文件
 * @param params
 */
export function getMinioTtsAudioFile(data:any) {
  return axios({
    method: 'get',
    responseType: 'blob',
    baseURL: origin+'/PeachBanquet/backend/api/TTSAudio?audio_id='+data.object_name+'&raw=false',
    headers: {
      'Content-Type': 'audio/wav;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
    }
  }).then(res=>{
    return res.data
  })
}

/**
 * 获取可以打开的ue实例并打开ue实例
 * @param params projectId
 */
export function getCanOpenAndOpenUe(data:any) {
  return axios({
    method:'post',
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
      // Satoken: 'e03cb4c8-2370-4184-9474-b37ba593ef15'
    },
    baseURL: `${baseAihumanCoreBusiniessApiUrl}/aiHumanUe/getCanOpenAndOpenUe`,
    data,
  }).then(res=>{
    return res.data
  })
}
/**
 * 关闭ue实例
 * @param params ueId serverId
 */
export function closeUe(data:any) {
  return axios({
    method:'post',
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
      // Satoken: 'e03cb4c8-2370-4184-9474-b37ba593ef15'
    },
    baseURL: `${baseAihumanCoreBusiniessApiUrl}/aiHumanUe/closeUe`,
    data,
  }).then(res=>{
    console.log('关闭ue')
    return res.data
  })
  // navigator.sendBeacon(`${baseAihumanCoreBusiniessApiUrl}/aiHumanUe/closeUe`, JSON.stringify(data));
  
}
/**
 * 获取可以打开的2d实例并打开2d实例
 * @param params projectId
 */
export function getCanOpenAndOpen2d(data:any) {
  return axios({
    method:'post',
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
      // Satoken: 'e03cb4c8-2370-4184-9474-b37ba593ef15'
    },
    baseURL: `${baseAihumanCoreBusiniessApiUrl}/aiHuman2d/resourceApply`,
    data,
  }).then(res=>{
    return res.data
  })
}
/**
 * 查询实例打开结果 轮询
 * @param params projectId
 */
export function get2dResourceApplyResult(data:any) {
  return axios({
    method:'post',
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
      // Satoken: 'e03cb4c8-2370-4184-9474-b37ba593ef15'
    },
    baseURL: `${baseAihumanCoreBusiniessApiUrl}/aiHuman2d/resourceApplyResult`,
    data,
  }).then(res=>{
    return res.data
  })
}
/**
 * 关闭2d实例
 * @param params projectId
 */
export function close2d(data:any) {
  return axios({
    method:'post',
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Access-Control-Allow-Origin': '*',
      // Satoken: 'e03cb4c8-2370-4184-9474-b37ba593ef15'
    },
    baseURL: `${baseAihumanCoreBusiniessApiUrl}/aiHuman2d/resourceRelease`,
    data,
  }).then(res=>{
    console.log('关闭2d')
    return res.data
  })
  // navigator.sendBeacon(`${baseAihumanCoreBusiniessApiUrl}/aiHuman2d/resourceRelease`, JSON.stringify(data));
  
}
